package LOGIN;

import mapper.impl.StudentMapperImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/del")
public class DelStudent extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String no = req.getParameter("no");
        String username =req.getParameter("name");
        if ((no == null )||(username == null )){
            req.setAttribute("error","学号或用户名不能为空");
            req.getRequestDispatcher("/error(Test).jsp").forward(req,resp);
            return;
        }

        StudentMapperImpl studel = new StudentMapperImpl();
        boolean stu = studel.DelStu(no,username);
//        进判断
        if (stu==false){
///           flase表示存储失败
            req.setAttribute("error","您选择删除的学号是："+no+"查无此号，请您重新输入");
            req.setAttribute("error","您选择删除的用户名是："+username+"查无此名，请您重新输入");
            req.getRequestDispatcher("/error(Test).jsp").forward(req,resp);
            return;
        }
        req.setAttribute("error","恭喜你存储成功了");
        req.getRequestDispatcher("/error(Test).jsp").forward(req,resp);
    }

}
